<?php
if (!defined('ZZQSS')){
	die("Access Denied");
}
/**
 * EmailLogClass類
 * add()
 * getdata()
 */
class EmailLogClass {
	var $db;
	var $table;
	var $tablepre;
	function __construct(){
		//設置全局變量
		global $db,$tablepre;
		$this->db=$db;
		$this->tablepre=$tablepre;
		$this->table=$tablepre."email_log";
	}
	function EmailLogClass() {
		$this->__construct();
	}
	/**
	 * 增加 log
	 *
	 * @param int $state  1  成功   0 失敗
	 * @return unknown
	 */
	function add($email,$state){
		if($email){
			$res = $this->db->query("INSERT INTO {$this->table} (email,state,datetime) VALUES('$email', '$state'  , now() )");												
			if($res){
				return true;
			}else{
				return false;
			}
		}else {
			return false;
		}


	}
	
	
	function getdata($limit="",$where="",$orderby=""){
		$tempdata=array();
		if(!empty($limit))$limit=" limit $limit ";
		if(!empty($where))$where=" where $where ";
		if(!empty($orderby))$orderby=" order by $orderby ";else $orderby=" order by id desc";
		$sql="select * from {$this->table}{$where}{$orderby}{$limit}";
		$query =$this->db->query($sql);
		while($value = $this->db->fetch_array($query)) {
			$tempdata[]=$value;
		}
		return $tempdata;
	
	}
	
	
	function getcount($where=""){
		if(!empty($where))$where=" where $where";
		$count= $this->db->result_first("Select count(*) From `$this->table` $where");
		return $count;
	}
	
	
}
?>